part of 'view.dart';

final _selectedType = ValueNotifier<KnowledgeBaseTypeTreeEntity?>(null);
final _types = ValueNotifier(<KnowledgeBaseTypeTreeEntity>[]);
final isNotPermissions = ValueNotifier(true);

Future<void> _fetchTypes() async {
  final resp = await HttpUtil()
      .generateGetRequest<List<KnowledgeBaseTypeTreeEntity>>(
        '${Interface.mainBaseUrl}/admin-api/system/knowledge-base-type/tree',
      )
      .execute();
  if (resp.isSucceed) {
    final data = resp.data;
    if (data == null) return;
    //KnowledgeBaseTypeTreeEntity树形数据 外层在套一层空的数据 所有
    final List<KnowledgeBaseTypeTreeEntity> a=[];
    final knowledgeBaseTypeTreeEntity = KnowledgeBaseTypeTreeEntity();
    knowledgeBaseTypeTreeEntity.label='所有';
    knowledgeBaseTypeTreeEntity.id=0;
    knowledgeBaseTypeTreeEntity.children = data;
    a.add(knowledgeBaseTypeTreeEntity);
    _types.value = a;
    isNotPermissions.value=true;
  }
  resp.onError((result) {
    if(result.code==403&&result.message=='没有该操作权限'){
      isNotPermissions.value=false;
    }
  });
}

Future<List<KnowledgeBaseInfoEntity>> _fecthList(
  int pageNum,
  int pageSize, {
  String? search,
}) async {
  final resp = await HttpUtil().generateGetRequest<List<KnowledgeBaseInfoEntity>>(
    '${Interface.mainBaseUrl}/admin-api/system/knowledge-base-information/page',
    queryParameters: {
      'pageNo': pageNum,
      'pageSize': pageSize,
      'typeId': _selectedType.value?.treeId,
      'fileName': _search,
    },
  ).execute();
  if (resp.isSucceed) {
    final data = resp.data;
    if (data != null) return data;
  }
  return [];
}

Future<KnowledgeBaseInfoEntity> fecthListDe(int? id) async {
  final resp = await HttpUtil().generateGetRequest<KnowledgeBaseInfoEntity>(
    '${Interface.mainBaseUrl}/admin-api/system/knowledge-base-information/get',
    queryParameters: {
      'id': id,
    },
  ).execute();
  if (resp.isSucceed) {
    final data = resp.data;
    if (data != null) return data;
  }
  return KnowledgeBaseInfoEntity();
}

String? _search;
